var e = require('../@babel/runtime/helpers/objectSpread2.js'),
  t = require('../@babel/runtime/helpers/typeof.js'),
  a = require('1E1DDD9770B67DCF787BB59075001B27.js'),
  n = a.baseUrl,
  o = a.systemType,
  r = (a.ENV, a.debug_key),
  i = require('33BAAF7370B67DCF55DCC774B1D21B27.js');
function s(a) {
  var n = parseInt(String(new Date().getTime() / 1e3));
  (a.timestamp = n),
    (a.sign_method = 'MD5'),
    (a.nonce_str = (function (e) {
      for (
        var t = '',
          a = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
          n = a.length,
          o = 0;
        o < e;
        o++
      )
        t += a.charAt(Math.floor(Math.random() * n));
      return t;
    })(16));
  for (
    var o = Object.keys(a).sort(), s = [], c = {}, d = {}, g = 0;
    g < o.length;
    g++
  ) {
    var l = o[g];
    if (a[l] || 0 === a[l])
      if ('object' === t(a[l])) {
        var u = JSON.stringify(a[l]).trim();
        s.push(''.concat(l, '=').concat(u)), (c[l] = u), (d[l] = JSON.parse(u));
      } else
        s.push(''.concat(l, '=').concat(String(a[l]).trim())),
          (c[l] = String(a[l]).trim()),
          (d[l] = String(a[l]).trim());
  }
  var h = encodeURIComponent(s.join('&')),
    m = '',
    p = '',
    f = '';
  try {
    var w = wx.getStorageSync('initSystem');
    (m = w.hasOwnProperty('client_config') ? w.client_config.mch_no : ''),
      (p = w.hasOwnProperty('client_config') ? w.client_config.app_id : ''),
      (f = w.hasOwnProperty('client_config') ? w.client_config.app_secret : '');
  } catch (e) {
    console.error('参数加密获取init数据异常: ', e);
  }
  var v = p + h + f + m;
  return e(
    r
      ? { debug_key: r, timestamp: n }
      : { sign: i.md5(v).toUpperCase(), timestamp: n },
    d,
  );
}
module.exports = function (t) {
  var a = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {},
    r = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : {},
    i = arguments.length > 3 && void 0 !== arguments[3] ? arguments[3] : {};
  return new Promise(function (c, d) {
    var g = e(
        {
          loading: !1,
          loadingDesc: 'loading...',
          auth: !0,
          errorKill: !0,
          thirdApi: !1,
          success: !1,
          successDesc: '操作成功',
          extendParams: !0,
          resolvePlainData: !1,
        },
        r,
      ),
      l = e(
        {
          Authorization: 'Bearer '.concat(wx.getStorageSync('accessToken')),
          'Sign-Client-Type': 'mp',
        },
        i.headers,
      );
    delete i.headers,
      g.loading && wx.showLoading({ title: g.loadingDesc, mask: !0 });
    var u = t.split(' ');
    if (
      (1 === u.length && u.unshift('get'),
      g.extendParams && (a.systemType = o),
      !a.referrer_uid)
    ) {
      var h = wx.getStorageSync('rid') || 0;
      a.referrer_uid = h;
    }
    var m = s(a);
    wx.request(
      e(
        {
          url: ''.concat(n, '/').concat(u[1]),
          data: m,
          header: l,
          method: u[0],
          success: function (e) {
            if ((g.loading && wx.hideLoading(), 200 === e.statusCode))
              return (
                40009 === e.data.code &&
                  (wx.setStorageSync('banned', 1),
                  wx.setStorageSync('bannedReason', e.data.data.cause),
                  wx.showToast({
                    title: '账号异常',
                    icon: 'none',
                    duration: 1200,
                  }),
                  wx.switchTab({ url: '/pages/index/index' })),
                0 === e.data.code
                  ? (g.success &&
                      wx.showToast({ title: g.successDesc, duration: 2e3 }),
                    void (g.resolvePlainData ? c(e.data) : c(e.data.data)))
                  : 401 === e.data.code || 403 === e.data.code
                    ? (wx.removeStorageSync('accessToken'),
                      g.auth &&
                        ('function' == typeof g.notLoginFunction
                          ? g.notLoginFunction(e.data)
                          : wx.navigateTo({ url: '/pages/login/login' })),
                      void d(e.data))
                    : 0 !== e.data.code
                      ? (console.log('fucking error', e.data.message),
                        g.errorKill &&
                          (e.data.message.length > 16
                            ? wx.showModal({
                                title: '提示',
                                content: e.data.message,
                                showCancel: !1,
                                confirmText: '知道了',
                              })
                            : wx.showToast({
                                title: e.data.message,
                                icon: 'none',
                                duration: 2e3,
                              })),
                        console.log('接口异常 :', u[1]),
                        void d(e.data))
                      : void 0
              );
            d(e);
          },
          fail: function (e) {
            g.loading && wx.hideLoading(), d(e);
          },
        },
        i,
      ),
    );
  });
};
